// Libraries import processing.serial.*; //Serial library // Variables and Objects Serial myPort; //create serial object PFont font; //Define Variables int time, distance, peak, ambient; String status; int sw = 1000; int sh = 1000; //window size width and height int baude = 115200; void setup() { //set window size (width, height) size(500,1000); //customize text font font = createFont("times new roman", 30); //custom fonts for buttons and title //printArray(Serial.list()); //list all available serial ports myPort = new Serial(this, Serial.list()[0], baude); //open the port being used (for me it is 0) and set baude rate } void draw() { //setup text fill(255,255,255); //text color to white (r,g,b) textFont(font); textAlign(CENTER); text("VL53L1X",width/2,30); //("text", x-coordinate, y-coordinate) text("status: " + status ,width/2,60); while (myPort.available() > 0 ) { String incoming = myPort.readStringUntil('\n'); if (incoming != null) { String[] list = split(incoming, ','); println(list[0]); //time println(list[1]); //distance println(list[2]); //status println(list[3]); //peak println(list[4]); //ambient if (list[2].equals("range valid")) { time = int(list[0]); distance = int(list[1]); status = list[2]; peak = int(list[3]); ambient = int(list[4]); } //close clean-up IF statement } //close reading IF statement background(0); //set black background text("Distance = " + distance +" (mm)",width/2,height/4+200); circle(width/2,height/4,map(distance,0,3600,0,400)); //circle(x, y, extent) //map(value, start1, stop1, start2, stop2) start/stop1 is current range, and start/stop2 is target range text("Peak signal = " + peak +" (MCPS)",width/2,height/2+250); circle(width/2,height/2+100,map(peak,0,100,0,400)); text("Ambient signal = " + ambient +" (MCPS)",width/2,3*height/4+200); circle(width/2,3*height/4+100,map(ambient,0,5,0,100)); } //close incoming data WHILE loop } //close void draw //println(incoming); //String inBuffer = myPort.readString(); //println(inBuffer); //int inByte = (myPort.read()); //println(inByte); // find framing //while (true && (myPort.available() >= 4) ) { /*byte1 = byte2; byte2 = byte3; byte3 = byte4; byte4 = (myPort.read()); if( (byte1 == 1) & (byte2 == 2) & (byte3 == 3) & (byte4 == 4) ) { break; } } //close while status = (myPort.read()); low = (myPort.read()); high = (myPort.read()); distance = (256*high+low); //if (status == 0) { print(status);print("\t");println(distance);*/